package com.example.shopingcenter.usercenter;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.shopingcenter.DateBase.LoginDbHelper;
import com.example.shopingcenter.R;
import com.example.shopingcenter.enity.User;

import java.util.Random;

public class Register extends AppCompatActivity {
    Button btnregister;
    EditText registerphone, registerpwd;
    private LoginDbHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        findView();


        btnregister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                User user=new User(registerphone.getText().toString(),registerpwd.getText().toString());
                Log.v("user",user.getName());
                boolean result= dbHelper.register(user);
                if (result){
                    Toast.makeText(Register.this, "注册成功！", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(Register.this,UserCenterLogin.class    );
                    startActivity(intent);
                }else {
                    Toast.makeText(Register.this, "注册失败", Toast.LENGTH_SHORT).show();
                }
            }
        });


    }

    private void findView() {

        btnregister = findViewById(R.id.btnregister);
        registerphone = findViewById(R.id.registerphone);

        registerpwd = findViewById(R.id.registerpwd);
        dbHelper = LoginDbHelper.getInstance(Register.this);
    }
}